package cn.matezk.lianlian.utils;

import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.json.JSONObject;

import java.util.Arrays;

public class TokenUtil {
    public static String createToken(String appKey, String secret, Long ts, JSONObject params) {
        String[] keyArray = params.keySet().toArray(new String[0]);
        Arrays.sort(keyArray);
        StringBuilder sb = new StringBuilder();
        sb.append(appKey);
        for (String key : keyArray) {
            sb.append(key).append(params.getStr(key));
        }
        sb.append(secret);
        sb.append(ts);
        String codes = sb.toString();
        return DigestUtil.sha1Hex(codes).toUpperCase();
    }
}
